import json

import requests
import pandas as pd
url = 'https://www.zhipin.com/wapi/zpgeek/search/joblist.json'

params = {
    "scene": 1,
    "query": "php",
    "city": "101230200",
    "page": 1,
    "pageSize": 30
}
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
    "cookie": "wd_guid=3a12f8f2-f2fa-4646-ae74-2398f576927c; historyState=state; _bl_uid=Ihlsscat31IbXUws3fbjnsmh4van; YD00951578218230%3AWM_NI=8t6rjKYSjeoOKdhSkl9S8L1hc5WCDOtIXz4%2BYN%2Fku88A2g%2Fda8og%2BQjDQqRHXXMFGXHqZXud4CcB6rbS8Et%2Bt94LOhJSJWJsoY6gzQ%2FnDHVjCCGCa2uOrSdKdeMaSHpHSVE%3D; YD00951578218230%3AWM_NIKE=9ca17ae2e6ffcda170e2e6ee90b562f3e7e1baf86eb8b48fa3c45b868e8bb1c845a1b5fc94aa44a2bafb8dae2af0fea7c3b92afcacfa93e9419b8da686ee4589bca8b4ea68fb8df8adb464a1eb99a4c745b897989bb7219b92e18cf834fc9ffe88ae70a3e8a188aa5baa9c9f92d1449c8883a7c6548caf96b9f870f89dada3b57aa28df8a6f721b8e7fcadce648a8d86b8c979ad87fa88f95bedb28ca9d562819d89a4e43ab791beb4e741a8bb8382d244b4989db7c837e2a3; YD00951578218230%3AWM_TID=byxoOuWi7JJEQAVAUBbRLN095uWKP91v; lastCity=101230200; gdxidpyhxdE=fTL35rUN6aM8EgtdMMqmHmDx4IIAjo0Yqm4B9akTXSKePDImjnZ7p2Bl2Gmays4q1Vaw9%5CpkHTRtV%2Bn%2F0ZMbcJ4Tk2wfoMxCrrbfhSl9ImMCOgzq%2F3junI58zHX%2Bop3ss1knEe4jk4sMLgHx29Qg9hK22TEIXnj8bf8tnf4q%2FVuguqVY%3A1677847175019; Hm_lvt_194df3105ad7148dcf2b98a91b5e727a=1677836720,1678542612; sid=sem_pz_bdpc_dasou_title; __zp_seo_uuid__=b55acce8-a8de-4e84-9a49-fa205b4069ae; __g=sem_pz_bdpc_dasou_title; boss_login_mode=app; wt2=DZQ4APl5OEV17X-w7RurwLUZeZDxqRcsRkDRszOtNZ79tRv61e4dsCljSzRtFtRnf45og_Vga6QtLsBEZYBEesQ~~; wbg=0; __zp_stoken__=3073eKX4wBWRqOQd1Q39Hc1wrS2BtLzk%2FLC90Ynx4HHpNfHIgU3wAMzhwbHUId2IffS5HLzx1SFE6BBJACUBQWBIwT0VaDVtwB2R9DygFaAdEST1%2FMwk7XEwDXUR6ADpqPxd1TjgON1htNGE%3D; __c=1679837247; __l=r=https%3A%2F%2Fwww.baidu.com%2Fother.php%3Fsc.K00000aItsIJV1_TC49jphTvWSV1PtvewTZFfC5xInXEPnfEvr48Rm49jC7r8pOVdFqH3I6HHe9SYFiD4VABjp99JEsT5pJb08364IAqR-CXUpXZkycCxhMv_WzdBu41_7b0aNtfASbYPHPqgkFkpsHEh5dUPh7zXHrHjKp1qFSJGmD_sWd-JtdPUyI7eruatT0Chy5sKxdt9nAt3ctnLyNt90wC.7D_NR2Ar5Od663rj6t8AGSPticrtXFBPrM-kt5QxIW94UhmLmry6S9wiGyAp7BEIu80.TLFWgv-b5HDkrfK1ThPGujYknHb0THY0IAYqmhq1TsKdTvNzgLw4TARqn0K9u7qYXgK-5Hn0IvqzujdBULP10ZFWIWYs0ZNzU7qGujYkPHfYrHRLnH6d0Addgv-b5HDdnWnvPjDz0AdxpyfqnHcknHbdP160UgwsU7qGujYknW6zP6KsI-qGujYs0A-bm1dri6KspyfqPfKWpyfqP100mLFW5Hf1nW6Y%26dt%3D1679837243%26wd%3Dboss%26tpl%3Dtpl_12826_31784_0%26l%3D1544957185%26us%3DlinkVersion%253D1%2526compPath%253D10036.0-10032.0%2526label%253D%2525E4%2525B8%2525BB%2525E6%2525A0%252587%2525E9%2525A2%252598%2526linkType%253D%2526linkText%253D&l=%2Fwww.zhipin.com%2Fweb%2Fgeek%2Fjob%3Fquery%3Dphp%26city%3D101230200&s=3&g=%2Fwww.zhipin.com%2Fxiamen%2F%3Fsid%3Dsem_pz_bdpc_dasou_title&friend_source=0&s=3&friend_source=0; __a=82334510.1671970216.1678542614.1679837247.60.8.14.14; geek_zp_token=V1RdIhEOP9319gXdNuxhUcKC657jzTxQ~~",
    "token": "HPGAOs42n5ufSoB",
    "zp_token": "V1RdIhEOP9319gXdNuxhUcKS215TnUwg~~",
    "referer": "https://www.zhipin.com/web/geek/job?query=php&city=101230200",
    "x-requested-with": "XMLHttpRequest",
    "traceid": "9720969A-E903-485F-BB8F-9EC8EEABCF2E",
    # "sec-ch-ua": "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "Windows",
    "sec-fetch-dest": "empty",
    "ec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin"
}
# 发送请求
response = requests.get(url, params=params, headers=headers)
data = json.loads(response.text)
print(response.text)
need_data = []
for job in data["zpData"]["jobList"]:

    need_data.append((job["jobName"],job["bossName"]))
print(need_data)
pd.DataFrame(need_data,columns=["岗位","boss名称"]).to_excel("Boos直聘数据.xlsx",index="False")